package com.aids_malaria.adapter;


import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.aids_malaria.R;
import com.aids_malaria.base.BaseQuickAdapter;
import com.aids_malaria.base.BaseViewHolder;
import com.aids_malaria.http.response.User;

import java.util.List;

public class AccountManagerAdapter extends BaseQuickAdapter<User> {

    private Option mOption;

    public AccountManagerAdapter(Context context, int layoutResID, List<User> data) {
        super(context, layoutResID, data);
    }

    public AccountManagerAdapter(Context context, int layoutResID, List<User> data, Option option) {
        this(context, layoutResID, data);
        this.mOption = option;
    }

    @Override
    public void convert(BaseViewHolder holder, User item) {
        if (holder.getAdapterPosition() % 2 > 0){
            holder.getView(R.id.item).setBackgroundColor(mContext.getResources().getColor(R.color.c_item2));
        }else {
            holder.getView(R.id.item).setBackgroundColor(mContext.getResources().getColor(R.color.c_item1));
        }
        CheckBox cb_check = (CheckBox) holder.getView(R.id.cb_check);
        cb_check.setChecked(item.isCheck());
        cb_check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(mOption != null){
                    mOption.onItemCheck(holder.getAdapterPosition(),b);
                }
            }
        });
        holder.setText(R.id.tv_login_account,item.getUser_code());
        holder.setText(R.id.tv_role,item.getRole_id());
        holder.setText(R.id.tv_account_name,item.getUser_name());
    }

    public interface Option{
        void onItemCheck(int position, boolean isCheck);
    }

}
